import grequests, time, collections


def qps_test(url, N):
    start_time = time.time()
    res_list = grequests.map([
        grequests.get(url)
        for _ in range(N)
    ])
    print(f'time: {time.time() - start_time}\nstatue_code:')
    print('\n'.join(
        f'{k}: {v}'
        for k, v in collections.Counter(
            res is None and 'LOST' or res.status_code
            for res in res_list
        ).items()
    ))


if __name__ == '__main__':
    qps_test('http://127.0.0.1:8001/test/hello', 1000)
    # qps_test('http://127.0.0.1:8000/hello', 10000)  # crashed
    # qps_test('http://127.0.0.1:8000/hello', 10000)  # crashed
